﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure.Coding;
using LinQProject;
using LinQProject.Repository;

namespace ServiceProject.EntityService
{
    public class OrderDetailService:DataBaseProcessBase<OrderDetail>
    {
        public OrderDetailService(FarmacieDataClassesDataContext database) : base(database)
        {}

        public void InsertOrderDetailsForOrder(IList<OrderDetail> listOrderDetail, int orderId)
        {
            foreach (var detail in listOrderDetail)
            {
                detail.OrderId = orderId;
                base.Add(detail, "OrderDetailId");
            }
        }

        //public IList<ProductDetail> GetProductDetails(IList<Order> listaOrder)
        //{
        //    IList<ProductDetail> listaProductDetail=new List<ProductDetail>();

        //    ProductDetail ProductDetailFirst=db.ProductDetails.First();
        //    if (listaOrder == null)
        //        listaProductDetail.Add(ProductDetailFirst);
        //    else
        //    {
        //        foreach (var order in listaOrder)
        //        {
        //            IList<OrderDetail> listaOrderDetails=order.OrderDetails;
        //            foreach (var orderDetail in listaOrderDetails)
        //            {
        //                int productDetailId = orderDetail.ProductDetailId;
        //                ProductDetail prod = Extensions<ProductDetail>.FindInList(listaProductDetail, 
        //                                                                            productDetail => productDetail.ProductDetailId == productDetailId);
        //                if (prod == null)
        //                    listaProductDetail.Add(orderDetail.ProductDetail);
        //            }
        //        }
        //    }
        //    return listaProductDetail;
        //}

        public IList<OrderDetail> GetOrderDetails(int orderId)
        {
            return base.GetAll(od => od.OrderId == orderId);
        }

        public IList<OrderDetail> GetAllOrderDetails()
        {
            return base.GetAll();
        }
    }
}
